package chapter06

object Test17_Extends {
  def main(args: Array[String]): Unit = {
    val alice = new Student17("alice", 18)
    alice.study()
    alice.sayHi()
    val person: Person17 = new Student17("bob", 20)
    person.sayHi()
    println("alice is Student17: " + alice.isInstanceOf[Student17])
    println("alice is Person17: " + alice.isInstanceOf[Person17])
    println("person is Student17: " + person.isInstanceOf[Student17])
    println("person is Person17: " + person.isInstanceOf[Person17])
    //类型转换
    if (person.isInstanceOf[Student17]) {
      val newStudent = person.asInstanceOf[Student17]
      newStudent.study()
      println(classOf[Student17])
    }
    //枚举类测试
    val monday = WorkDay.MONDAY
    println(monday)
  }
}


class Person17(val name: String, val age: Int) {
  def sayHi(): Unit = println("hi from person: " + name)
}

class Student17(name: String, age: Int) extends Person17(name, age) {
  override def sayHi(): Unit = println("hi from student: " + name)

  def study() = println("study")
}

//定义枚举类
object WorkDay extends Enumeration {
  val MONDAY = Value(1, "Monday")
  val TUESDAY = Value(2, "Tuesday")
}

//定义应用类对象
object TestApp extends App {
  println("App Start")

  //类型重命名
  type MyString = String
  val a: MyString = "abc"
  println(a)
}